package com.company.finance.ddd.domain.core.voucher;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author wanglei
 * @version $$Id: AccountingDocument, v 0.1 2021/1/28 10:46 wanglei Exp $$
 */
@AllArgsConstructor
@Builder
@Data
public class Voucher {

    public Voucher() {
    }

    private Long       ID;
    private String     VOUCHER_MAIN_NO;
    private Long       BILL_ID;
    private String     BILL_NO;
    private String     BILL_NO_RELATED;
    private String     BILL_TYPE_CODE;
    private String     BILL_TYPE_KIND;
    private String     COMPANY_CODE;
    private String     COMPANY_NAME;
    private String     SUPPLIER_CODE;
    private String     SUPPLIER_NAME;
    private String     CURRENCY_CODE;
    private String     CURRENCY_NAME;
    private BigDecimal RATE;
    private Date       BIZ_DATE;
    private String     SUBMIT_NAME;
    private String     SUBMIT_NO;
    private String     PROPOSER_NAME;
    private String     PROPOSER_NO;
    private String     FIN_RECHECKER_NAME;
    private String     FIN_RECHECKER_NO;
    private Integer    FILE_NUMBER;
    private String     STATE;
    private Integer    DEL_FLAG;
    private String     REMARK;
    private String     BILL_JSON;
    private String     IS_RELATED_PARTY;
    private String     VOUCHER_NO;
    private Long       VOUCHER_MAIN_ID;
    private Date       ACC_DATE;
    private String     PERIOD_YEAR;
    private String     PERIOD_CODE;
    private String     VOUCHER_KIND;
    private String     VOUCHER_TYPE;
    private String     VOUCHER_TYPE_NAME;
    private String     EAS_VOUCHER_TYPE;
    private Integer    PUSH_TYPE;
    private String     EAS_NO;
    private String     EAS_INFO;
    private String     BASE_CURRENCY_CODE;
    private String     BASE_CURRENCY_NAME;
    private Date       SEND_TIME;
    private Long       CREATOR;
    private Long       UPDATER;
    private Date       CREATE_TIME;
    private Date       UPDATE_TIME;
    private List<VoucherItem> items;

    private VoucherService voucherService;

    public Voucher voucherService(VoucherService voucherService) {
        this.voucherService = voucherService;
        return this;
    }

    public Voucher setItems(List<VoucherItem> items) {
        this.items = items;
        return this;
    }

    public List<VoucherItem> getItems() {
        if (null != items && !items.isEmpty()) {
            return items;
        }
        Map<String, Object> param = new HashMap<>(1);
        param.put("voucher_id", ID);
        return voucherService.getVoucherItemIRepository().query(param);
    }

    @Override
    public String toString() {
        return "Voucher{" +
                "ID=" + ID +
                ", VOUCHER_MAIN_NO='" + VOUCHER_MAIN_NO + '\'' +
                ", BILL_ID=" + BILL_ID +
                ", BILL_NO='" + BILL_NO + '\'' +
                ", BILL_NO_RELATED='" + BILL_NO_RELATED + '\'' +
                ", BILL_TYPE_CODE='" + BILL_TYPE_CODE + '\'' +
                ", BILL_TYPE_KIND='" + BILL_TYPE_KIND + '\'' +
                ", COMPANY_CODE='" + COMPANY_CODE + '\'' +
                ", COMPANY_NAME='" + COMPANY_NAME + '\'' +
                ", SUPPLIER_CODE='" + SUPPLIER_CODE + '\'' +
                ", SUPPLIER_NAME='" + SUPPLIER_NAME + '\'' +
                ", CURRENCY_CODE='" + CURRENCY_CODE + '\'' +
                ", CURRENCY_NAME='" + CURRENCY_NAME + '\'' +
                ", RATE=" + RATE +
                ", BIZ_DATE=" + BIZ_DATE +
                ", SUBMIT_NAME='" + SUBMIT_NAME + '\'' +
                ", SUBMIT_NO='" + SUBMIT_NO + '\'' +
                ", PROPOSER_NAME='" + PROPOSER_NAME + '\'' +
                ", PROPOSER_NO='" + PROPOSER_NO + '\'' +
                ", FIN_RECHECKER_NAME='" + FIN_RECHECKER_NAME + '\'' +
                ", FIN_RECHECKER_NO='" + FIN_RECHECKER_NO + '\'' +
                ", FILE_NUMBER=" + FILE_NUMBER +
                ", STATE='" + STATE + '\'' +
                ", DEL_FLAG=" + DEL_FLAG +
                ", REMARK='" + REMARK + '\'' +
                ", BILL_JSON='" + BILL_JSON + '\'' +
                ", IS_RELATED_PARTY='" + IS_RELATED_PARTY + '\'' +
                ", VOUCHER_NO='" + VOUCHER_NO + '\'' +
                ", VOUCHER_MAIN_ID=" + VOUCHER_MAIN_ID +
                ", ACC_DATE=" + ACC_DATE +
                ", PERIOD_YEAR='" + PERIOD_YEAR + '\'' +
                ", PERIOD_CODE='" + PERIOD_CODE + '\'' +
                ", VOUCHER_KIND='" + VOUCHER_KIND + '\'' +
                ", VOUCHER_TYPE='" + VOUCHER_TYPE + '\'' +
                ", VOUCHER_TYPE_NAME='" + VOUCHER_TYPE_NAME + '\'' +
                ", EAS_VOUCHER_TYPE='" + EAS_VOUCHER_TYPE + '\'' +
                ", PUSH_TYPE=" + PUSH_TYPE +
                ", EAS_NO='" + EAS_NO + '\'' +
                ", EAS_INFO='" + EAS_INFO + '\'' +
                ", BASE_CURRENCY_CODE='" + BASE_CURRENCY_CODE + '\'' +
                ", BASE_CURRENCY_NAME='" + BASE_CURRENCY_NAME + '\'' +
                ", SEND_TIME=" + SEND_TIME +
                ", CREATOR=" + CREATOR +
                ", UPDATER=" + UPDATER +
                ", CREATE_TIME=" + CREATE_TIME +
                ", UPDATE_TIME=" + UPDATE_TIME +
                ", items=" + items +
                ", voucherService=" + voucherService +
                '}';
    }

    @AllArgsConstructor
    @Builder
    @Data
    public static class VoucherItem {
        public VoucherItem() {
        }

        private Long       ID;
        private Long       VOUCHER_ID;
        private Integer    ENTRY_SEQ;
        private String     DIGEST;
        private String     ACC_SUBJECT;
        private String     ACC_SUBJECT_NAME;
        private String     ACC_SUBJECT_NAME_LONG;
        private Integer    DC_FLAG;
        private BigDecimal ORIGINAL_AMOUNT;
        private BigDecimal DEBIT_AMOUNT;
        private BigDecimal CREDIT_AMOUNT;
        private Integer    CUSSENT;
        private Integer    CASH_ITEM_FLAG;
        private Long       CREATOR;
        private Long       UPDATER;
        private Date       CREATE_TIME;
        private Date       UPDATE_TIME;
        private String     FEE_JSON;
        private String     PUSH_FLAG;
        private String     AMORTIZE_ACC_SUBJECT;
        private String     AMORTIZE_ACC_SUBJECT_NAME_LONG;
        private String     AMORTIZE_START_MONTH;
        private String     AMORTIZE_END_MONTH;
    }
}
